<%@page import="br.com.Modelo.UsuarioCliente"%>
<%@page import="java.util.List"%>
<%@page import="br.com.Modelo.Produto"%>
<%@page import="br.com.Modelo.UsuarioComerciante"%>
<%@page import="br.com.Modelo.Pagina"%>
<%@page import="br.com.Modelo.Endereco"%>
<%@page import="br.com.Dao.UsuarioClienteDao"%>
<%@page import="br.com.Dao.UsuarioComercianteDao"%>
<%@page import="br.com.Dao.ProdutoDao"%>
<%@page import="br.com.Dao.PaginaDao"%>
<%@page import="br.com.Dao.CupomDao"%>
<%@page import="br.com.Modelo.Cupom"%>
<%@page import="br.com.Dao.EnderecoDao"%>
<%@page import="java.io.IOException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Painel Administrativo</title>

<!-- Bootstrap Core CSS -->
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="../public/css/sb-admin.css" rel="stylesheet">

<!-- Morris Charts CSS -->
<link href="../public/css/plugins/morris.css" rel="stylesheet">

<!-- Custom Fonts -->
<link href="../public/font-awesome-4.1.0/css/font-awesome.min.css"
	rel="stylesheet" type="text/css">

<script type="text/javascript" src="../public/js/jquery.js"></script>


<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


<style>
.btn-primary {
	color: #ffffff;
	text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
	background-color: #229ac8;
	background-image: linear-gradient(to bottom, #23a1d1, #1f90bb);
	background-repeat: repeat-x;
	border-color: #1f90bb #1f90bb #145e7a;
}

.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]
	{
	background-color: #1f90bb;
	background-position: 0 -15px;
}

#capa {
  filter: gray; /* IE6-9 */
  -webkit-filter: grayscale(1); /* Google Chrome, Safari 6+ & Opera 15+ */
    -webkit-box-shadow: 0px 1px 3px 2px rgba(0,0,0,0.75);
    -moz-box-shadow: 0px 1px 3px 2px rgba(0,0,0,0.75);
    box-shadow: 0px 1px 3px 2px rgba(0,0,0,0.75);
    margin-bottom:10px;
}


</style>

<script>
	$(document)
			.ready(
					function() {
						var i = 1;

						$("#add_row")
								.click(
										function() {
											if (i != 3) {
												$('#addr' + i)
														.html(
																"<td>"
																		+ (i + 1)
																		+ "</td><td><input name='name"+i+"' type='text' placeholder='Name' class='form-control input-md'  /> </td> ");

												$('#tab_logic').append(
														'<tr id="addr'
																+ (i + 1)
																+ '"></tr>');
												i++;

											}

										});

						$("#delete_row").click(function() {
							if (i > 1) {
								$("#addr" + (i - 1)).html('');
								i--;
							}
						});

					});

	function carregaDadosEndJSon(id_cliente) {

		var jsonData = JSON.stringify(jsonDataObject);

		$.getJSON("responce.jsp", {
			action : "export",
			json : jsonData
		}, function(data) {
			alert(data.message);
			$('#return_message').html(data.message);
		});

	}

	/* $(document).ready(function(){
	 	  $("#EditEnd").on('show.bs.modal',function(event){
	 		  var button = $(event.relatedTarget);
	 		  var recipient = button.data('whatever');

	 		  alert("HTML: " +recipient);

	 		  $.get('/plataforma_marketing/admin/responce.jsp',{id:recipient},function(data) {   

		        $('#nome').val(data.cep);
		      alert("HTML: " +data.cep);             
	          
	        });
	 		  
	 	  });
	 	  
	 	  $("#btn2").click(function(){
	 	    alert("HTML: " + $("#test").html());
	 	  });

	 		  
	 	});*/

	function carregaDadosClienteJSon(id_cliente) {
		$.post('responce.jsp', {
			id_cliente : id_cliente
		}, function(data) {
			$('#nome').val(data.nome);
			$('#email').val(data.email);
			$('#id_cliente').val(data.id_cliente);
		}, 'json');
	}

	function janelaEditarCliente(id_cliente) {

		//antes de abrir a janela, preciso carregar os dados do cliente e preencher os campos dentro do modal
		carregaDadosClienteJSon(id_cliente);

		$('#modalEditarCliente').modal('show');
	}

	$(document).ready(function() {
		$('#submit').click(function(event) {
			var username = $('#user').val();
			alert("" + username);
			$.get('jsonServelt', {
				user : username
			}, function(responseText) {
				$('#welcometext').text(responseText);
			});
		});
	});

	$(document).ready(function() {
		//$('#p').click(function() {
			$("#EditEnd").on('show.bs.modal', function(event) {
				var button = $(event.relatedTarget);
				var recipient = button.data('whatever');
				//alert("sdsd"+recipient);

				$.ajax({
					url : 'jsonServelt',
					type : 'post',
					dataType : 'json',
					data : {
						campo1 : recipient
					},
					success : function(data) {
						$('#cep').val(data.cep);
						$('#cidade').val(data.cidade);
						$('#bairro').val(data.bairro);
						$('#numero').val(data.numero);
						$('#rua').val(data.rua);
						$('#id_pagina').val(data.id_pagina);
						$('#count').val(data.count);
						$('#telefone').val(data.telefone);
						$('#id_end').val(data.id);
					}
				});
			});
		//});
	});
</script>
</head>

<body>

	<%
		///allow access only if session exists
	    
		String[] id = (String[]) session.getAttribute("user");	    
		UsuarioCliente userCliente = null;		
		UsuarioClienteDao dao = new UsuarioClienteDao();
		
		if (id != null) {
			
			if (id[1].equals("1")) {
				userCliente = dao.validaAutenticacaoUser(
				Long.parseLong(id[0]), Integer.parseInt(id[1]));

			} else {

			}
		}
		String userName = null;
		String sessionID = null;
		
	//	out.println(userCliente.getLogin());
		
		if (userCliente != null) {
			
			Cupom cup = new Cupom();
			CupomDao cupd = new CupomDao();
			List<Cupom> cupons;
			cupons = cupd.getCupom((int)userCliente.getId());
			Cupom cupomAtual = cupd.getCupomAtivo(userCliente.getId());

	%>
	<div id="wrapper">

		<!-- Navigation -->
		<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<!-- Brand and toggle get grouped for better mobile display -->
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-ex1-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="">Painel Administrativo</a>
		</div>
		<!-- Top Menu Items -->
		<ul class="nav navbar-right top-nav">

			<!--  if for logado -->
			<%
				//if(userComerciante != null){
			%>
			<li class="dropdown"><a class="dropdown-toggle" role="button"
				data-toggle="dropdown" href="#"> <i
					class="glyphicon glyphicon-user"></i> <%=userCliente.getLogin()%>
					<span class="caret"></span></a>
				<ul id="g-account-menu" class="dropdown-menu" role="menu">
					<li><a href="#">Meu Perfil</a></li>
					<li><a href="/plataforma_marketing/LogoutServlet"><i class="glyphicon glyphicon-lock"></i>
							Sair</a></li>
				</ul></li>
			<%
				//}
			%>



		</ul>
		<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
		<div class="collapse navbar-collapse navbar-ex1-collapse">
			<ul class="nav navbar-nav side-nav">
				<li class="co"><a href="/plataforma_marketing"><img
						src="/plataforma_marketing/img/logo.png"></img> </a></li>

				<li class=""><a href="config_conta.jsp"><i
						class="fa fa-fw fa-file"></i> Configurações da Conta</a></li>

				<li class=""><a href="admin_cliente.jsp"><i
						class="fa fa-fw fa-file"></i> Visualizar Cupons</a></li>
			</ul>
		</div>
		<!-- /.navbar-collapse --> </nav>

		<div id="page-wrapper" style="height: 100%">

			<div class="container-fluid" style="height: 1000px"  >

				<!-- Page Heading -->
				<div class="row">
					<div class="panel panel-default">
						<div class="panel-heading">
							<div class="panel-title">
								<i class="glyphicon glyphicon-wrench pull-right"></i>
								<h4>Meus Cupons</h4>
							</div>
						</div>
						<div class="panel-body">

Cupons Completos: <%=cupd.qtd_Cupons((int)userCliente.getId())%>

<br/><br/>
Porcentagem do Cupom Atual:
<br/><br/>
  <% if(cupd.qtd_Cupons((int)userCliente.getId()) != 4){ %>
<div class="progress">

  <div class="progress-bar" role="progressbar" aria-valuenow="<%=cupomAtual.getProgresso() %>" aria-valuemin="0" aria-valuemax="100" style="width: <%=cupomAtual.getProgresso() %>%;">
   
    <%=cupomAtual.getProgresso() %>%
  </div>
  

</div>
  <%}else{ %>
    <h3>Todos os cupons estao completos</h3>
  <%} %>
							</div>



						</div>
						<!--/panel content-->

					</div>
					<!--/panel-->
					


				</div>
				<!--/panel content-->
			</div>
			<!--/panel-->
		
				
		</div>
		<!-- /.row -->



	</div>
	<!-- /.container-fluid -->

	</div>
	<!-- /#page-wrapper -->

	</div>
	<!-- /#wrapper -->

	<!-- jQuery Version 1.11.0 -->
	<!-- Bootstrap Core JavaScript -->



	<script src="../bootstrap/js/jquery-1.11.0.js"></script>
	<script src="../bootstrap/js/bootstrap.js"></script>




	<!-- Morris Charts JavaScript -->


	<%
						}
					%>

</body>

</html>